package com.web;

import com.domain.User;
import com.service.userService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 员工请求,展示所有用户
 * 提交到 userService 的 showAllUser 函数
 * 转发到 /userShow.jsp 页面进行展示
 */
@WebServlet("/showUser")
public class ShowUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1先读取所有的用户
        userService user = new userService();
        List<User> all = user.showAllUser();
        System.out.println("显示所有用户");

        //2将数据存到/userShow.jsp进行展示
        request.setAttribute("list",all);//存入数据
        request.getRequestDispatcher("/userShow.jsp").forward(request,response);//进行转发
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
